new Vue({
  el: '#app',
  data() {
    return {
      form: {
        type: "0",
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      total: 0,
      tableData: [],		//表格数据
    }
  },
  mounted() {
    this.getList(this.form)
  },
  methods: {
    onSerach() {				//查询方法
      console.log("搜搜")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      const _this = this
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getOrderFinancingAll?token=${$.cookie('token')}`,
        data,
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = '../../../'+XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          _this.tableData = Result.tableData
          _this.total = parseInt(Result.limit)
        },
        dataType: "json"
      });
    },
    editMember(row) {
      sessionStorage.setItem("order_financing_info", JSON.stringify(row))
      window.location.href = 'Contract.html'
    },
    deletMember(Order_Financing_SerialNumber){
      const _this = this;
      this.$prompt('请输入驳回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^(?!\s*$).+/,
        inputErrorMessage: '原因不能由零个或多个空格组成',
        type: 'warning',
      }).then(({ value }) => {
        _this.delete(Order_Financing_SerialNumber,value)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        });
      });
    },
    delete(Order_Financing_SerialNumber,Reason) {
      const _this = this
      $.ajax({
        url: DomainName + '/GoodsInquiryKeyOriginal',
        type: 'POST',
        data:{
          Data:'order_financing_info',
          Primary_Key:Order_Financing_SerialNumber,
          Primary_Key_Name:'Order_Financing_SerialNumber'
        },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '2'
            let obj = {
              Order_Financing_Log_SerialNumber:'',
              Order_Financing_SerialNumber,
              Operate:'2',
              TIME:getYMDHMSDate(),
              Reason
            }
            $.ajax({
              url: `${DomainName}/getEditAction?token=${$.cookie("token")}`,
              type: 'POST',
              data:{ Data: JSON.stringify({ 
                Modify: { order_financing_info: [res[0]] } ,
                Add: { order_financing_log:[obj] }
              }) },
              success:function (res) {
                if (res.Status == 'success') {
                  _this.getList(_this.form);
                  _this.$message({
                    type: 'success',
                    message: '驳回成功!'
                  });
                }
              },
              error: function () {
                _this.$message.error("删除失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            })
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  },
})
